package com.erli.exchange.common.sg.mapper;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementRefs;
import javax.xml.bind.annotation.XmlMixed;
import javax.xml.bind.annotation.XmlRootElement;

import com.erli.exchange.core.util.JAXBUtil;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Setter;

//<update id="updateUserCoupon" parameterType="UserCouponEntity">
//	update 
//		<include refid="BASE_TABLE"/>
//		<set> 
//			<if test="property != null and property!=''">
//				property=#{property},
//			</if>
//			<if test="userid != null and userid!=''">
//				userid=#{userid},
//			</if>
//			<if test="activityid != null and activityid!=''">
//				activityid=#{activityid},
//			</if>
//			<if test="amount != null and amount!=''">
//				amount=#{amount},
//			</if>
//			<if test="usecondition != null and usecondition!=''">
//				usecondition=#{usecondition},
//			</if>
//			<if test="sendtime != null and sendtime!=''">
//				sendtime=#{sendtime},
//			</if>
//			<if test="usedtime != null and usedtime!=''">
//				usedtime=#{usedtime},
//			</if>
//			<if test="bookorderid != null and bookorderid!=''">
//				bookorderid=#{bookorderid},
//			</if>
//			<if test="starttime != null and starttime!=''">
//				starttime=#{starttime},
//			</if>
//			<if test="endtime != null and endtime!=''">
//				endtime=#{endtime},
//			</if>
//			<if test="source != null and source!=''">  	
//				source=#{source}
//			</if>
//		</set>
//	where id=#{id}
//</update> 
@Setter
@AllArgsConstructor
@NoArgsConstructor
@XmlRootElement(name = "update")
public class Update {
	
	@XmlAttribute
	private String id;
	@XmlAttribute
	private String parameterType;
	
	@XmlElementRefs(value = { 
			@XmlElementRef(name = "include", type = Include.class),
			@XmlElementRef(name = "set", type = Set.class)
			})
	@XmlMixed
	private List<Object> list;
	
	public static void main(String[] args) throws Exception {
	
		List<If> ifList = new ArrayList<If>();
		If if1 = new If();
		if1.setTest("userName != null and userName != '' ");
		if1.setValue("userName=#{userName},");
		If if2 = new If();
		if2.setTest("userNameCn != null and userNameCn != ''");
		if2.setValue("userNameCn=#{userNameCn},");
		ifList.add(if1);
		ifList.add(if2);
		
		List<Object> list = new ArrayList<>();
		list.add("update");
		list.add(new Include("BASE_TABLE"));
		list.add(new Set(ifList));
		list.add("where id=#{id}");
		
		//<update id="updateUserCoupon" parameterType="UserCouponEntity">
		Update update = new Update("updateUserCoupon", "UserCouponEntity", list);
		System.out.println(JAXBUtil.toXML(update));
	}

}
